var express = require('express')
var bodyParser = require('body-parser');
var app = express();
var nodemailer = require('nodemailer');





app.use(bodyParser.urlencoded({ extended: false }));
app.post('/hello', function (req, res) {
    //跨域补充
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers',
        'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
    //跨域补充结束

    console.log(req.body.title)
    console.log(req.body.text)
    res.send({ title: req.body.title, text: req.body.text });


    var transporter = nodemailer.createTransport({
        host: "smtp.exmail.qq.com", // 主机
        secure: true, // 使用 SSL
        port: 465, // SMTP 端口
        auth: {
            user: 'devchainmail@meng.im',//发送者
            pass: 's0v7DXBlB2YvUSHi' //授权码,通过QQ获取  

        }
    });
    var mailOptions = {
        from: 'devchainmail@meng.im', // 发送者  
        to: '2595488832@qq.com', // 接受者,可以同时发送多个,以逗号隔开  
        subject: req.body.title, // 标题  
        html: req.body.text, // 文本  
    };

    transporter.sendMail(mailOptions, function (err, info) {
        if (err) {
            console.log(err);
            return;
        }

        console.log('发送成功');
    })


});
app.listen(3000)